package cn.com.code.generator.controller;

import cn.com.code.generator.entity.TaskStatus;
import cn.com.code.generator.service.TaskStatusService;
import cn.com.do1.dsf.common.annotation.SysLog;
import cn.com.do1.dsf.common.validator.group.AddGroup;
import cn.com.do1.dsf.common.validator.group.UpdateGroup;
import cn.com.do1.dsf.common.web.BaseRestController;
import cn.com.do1.dsf.compont.mysql.utils.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Arrays;
import java.util.Map;


/**
 * 
 *
 * @author nick
 * @email sunlightcs@gmail.com
 * @date 2021-04-23 01:37:42
 */
@Api(tags = "")
@RestController
@RequestMapping("/task/status")
public class TaskStatusController extends BaseRestController {
    @Autowired
    private TaskStatusService taskStatusService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "taskDefinitionKey", value="", paramType = "query"),
            @ApiImplicitParam(name = "status", value="", paramType = "query"),
            @ApiImplicitParam(name = "page", value="页码", paramType = "query" ,required = true, defaultValue = "1"),
            @ApiImplicitParam(name = "limit", value="每页条数", paramType = "query",required = true, defaultValue = "10"),
            @ApiImplicitParam(name = "sidx", value="排序字段", paramType = "query"),
            @ApiImplicitParam(name = "order", value="排序方式，如：asc、desc",  paramType = "query")
    })
    public PageUtils<TaskStatus> list(@ApiIgnore @RequestParam Map<String, Object> params){
        PageUtils<TaskStatus> page = taskStatusService.queryPage(params);

        return page;
    }


    /**
     * 信息
     */
    @GetMapping("/{id}")
    @ApiOperation("获取信息")
    @ApiImplicitParam(name = "id", value = "ID",paramType="path", required = true)
    public TaskStatus info(@PathVariable("id") Long id){
        logger.info("id="+id);
		TaskStatus taskStatus = taskStatusService.selectById(id);

        return taskStatus;
    }

    /**
     * 保存
     */
    @SysLog("保存")
    @PostMapping("/save")
    @ApiOperation("保存")
    public TaskStatus save(@Validated(AddGroup.class) @RequestBody TaskStatus taskStatus){
        taskStatusService.insert(taskStatus);

        return taskStatus;
    }

    /**
     * 修改
     */
    @SysLog("修改")
    @PutMapping("/{id}")
    @ApiOperation("修改")
    public TaskStatus update(@Validated(UpdateGroup.class) @RequestBody TaskStatus taskStatus){
		taskStatusService.updateById(taskStatus);

        return taskStatus;
    }

    /**
     * 删除
     */
    @SysLog("删除")
    @DeleteMapping("/")
    @ApiOperation("删除")
    public void delete(@RequestBody Long[] ids){
		taskStatusService.deleteBatchIds(Arrays.asList(ids));

    }

}
